class Singleton {//饿汉式
    private static Singleton instance = new Singleton();

    private Singleton() {//私有构造方法，防止类外创建对象

    }

    public static Singleton getInstance() {
        return instance;
    }
}

public class Demo1 {
    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getInstance();
        Singleton singleton2 = Singleton.getInstance();

        System.out.println(singleton1 == singleton2);

//        Singleton singleton3 = new Singleton();
    }
}